﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Drawing.Design;

namespace Clandestine.Entities
{
    // The UITypeEditor for the propertygrid
    // Uses a delegate because the code must reside here so we dont have circular dependancies
    // but the code must use Slick's stuff... BLAH. We set the delegate in Slick.Tools.Selection so just pretend
    // that mess doesn't happen!
    public delegate object DoSelection(object value);
    public class SelectionUITypeEditor : UITypeEditor
    {
        public static DoSelection DoSelection;

        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (DoSelection != null)
                return DoSelection(value);
            return value;
        }
    }

    public class RandomWalkingNPC : SimpleDialogueNPC
    {
        public int MovementChance { get; set; }

        [Editor(typeof(SelectionUITypeEditor), typeof(UITypeEditor))]
        public Rectangle MovementRectangle { get; set; }

        protected override void tick(float deltaMs)
        {
            // Is it already moving somewhere?
            if (this.IsMoving)
            {
                // If so, watch out for collisions
                if (this.hasCollided)
                {
                    base.moveDstCoord = base.Position;
                    this.hasCollided = false;
                }
            }
            else
            {
                // If not, work out if we're going to!
                if (WorldMap.Rand.Next(0, 100) > MovementChance)
                    base.MoveTo(false, MoveSpeed.Walk, new System.Drawing.Point(WorldMap.Rand.Next(MovementRectangle.Left, MovementRectangle.Right), WorldMap.Rand.Next(MovementRectangle.Top, MovementRectangle.Bottom)), null);
            }
            base.tick(deltaMs);
        }

    }
}
